package com.socked;

import java.io.IOException;
import java.io.ObjectInputStream;
import java.io.ObjectOutputStream;
import java.net.ServerSocket;
import java.net.Socket;
import java.util.Scanner;

public class Server {
  public static void main(String[] args) throws IOException, ClassNotFoundException {
    // 启动服务器
    ServerSocket server = new ServerSocket(8888);
    System.out.println("服务器已启动，等待连接");
    Socket socket = server.accept(); // 等待连接 监听  会阻塞

    ObjectOutputStream out = new ObjectOutputStream(socket.getOutputStream());
    ObjectInputStream in = new ObjectInputStream(socket.getInputStream());

    Scanner sc = new Scanner(System.in);

    while(true){

      response r = new response("欢迎光临");
      out.writeObject(r);
      request request = (request)in.readObject();
      System.out.println("用户说："+request.getMsg());
    }
  }
}
